/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Temporal;
import type.ShippingOrderStatus;

/**
 *
 * @author wei
 */
@Entity(name="ShippingOrder")
public class ShippingOrderEntity extends DataObjectEntity implements Serializable {
    
    @ManyToOne
    private AddressEntity address;    
    @OneToOne(cascade= CascadeType.ALL, mappedBy="shippingOrder")
    private PackingOrderEntity packingOrder;    
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date dateToShip;    
    private ShippingOrderStatus status;
    
    @ManyToOne
    private BillingRequestEntity billingRequest;
    @ManyToOne
    private SalesOrderEntity salesOrder;
    
    public ShippingOrderEntity() {
        super();
    }

    public AddressEntity getAddress() {
        return address;
    }

    public void setAddress(AddressEntity address) {
        this.address = address;
    }

    public Date getDateToShip() {
        return dateToShip;
    }

    public void setDateToShip(Date dateToShip) {
        this.dateToShip = dateToShip;
    }

    public SalesOrderEntity getSalesOrder() {
        return salesOrder;
    }

    public void setSalesOrder(SalesOrderEntity salesOrder) {
        this.salesOrder = salesOrder;
    }

    public ShippingOrderStatus getStatus() {
        return status;
    }

    public void setStatus(ShippingOrderStatus status) {
        this.status = status;
    }

    public BillingRequestEntity getBillingRequest() {
        return billingRequest;
    }

    public void setBillingRequest(BillingRequestEntity billingRequest) {
        this.billingRequest = billingRequest;
    }

    public PackingOrderEntity getPackingOrder() {
        return packingOrder;
    }

    public void setPackingOrder(PackingOrderEntity packingOrder) {
        this.packingOrder = packingOrder;
    }
    
    public List<ProductQuantityPriceEntity> getPQPs(){
        List<ProductQuantityPriceEntity> pqps = new ArrayList<ProductQuantityPriceEntity>();
        for(ShippingRequestEntity shippingRequest : packingOrder.getProductToQuantity()){
            pqps.add(shippingRequest.getPQP());
        }
        return pqps;
    }

    @Override
    public String childToString() {
        return "ShippingOrderEntity{" + "address=" + address + ", packingOrder=" + packingOrder + ", dateToShip=" + dateToShip + ", status=" + status + ", billingRequest=" + billingRequest + ", salesOrder=" + salesOrder + '}';
    }
    
}
